package com.youbug.mall.product_pms.controller;


import com.youbug.common.vo.CommonSelectVo;
import com.youbug.common.vo.CommonTreeVo;
import com.youbug.common.vo.QueryVo;
import com.youbug.mall.product_pms.entity.PmsSkuInfo;
import com.youbug.mall.product_pms.service.IPmsSkuInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/pmsSkuInfo")
public class PmsSkuInfoController {
@Autowired
private IPmsSkuInfoService pmsSkuInfoService;

    @PostMapping("/getPmsSkuInfoPage")
    public R<IPage<PmsSkuInfo>> getPmsSkuInfoPage(@RequestBody QueryVo<PmsSkuInfo> queryVo){

        IPage<PmsSkuInfo> pmsSkuInfos = pmsSkuInfoService.getPmsSkuInfoPage(queryVo);

        return R.ok(pmsSkuInfos);
    }

    @GetMapping("/getPmsSkuInfoById/{id}")
    public R<PmsSkuInfo> getPmsSkuInfoById(@PathVariable Integer id){

        PmsSkuInfo pmsSkuInfo = pmsSkuInfoService.getById(id);

        return R.ok(pmsSkuInfo);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody PmsSkuInfo spuSaveVo){

        boolean save = pmsSkuInfoService.save(spuSaveVo);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody PmsSkuInfo pmsSkuInfo){

        boolean update = pmsSkuInfoService.updateById(pmsSkuInfo);

        return  R.ok(update);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Integer id){

        boolean remove = pmsSkuInfoService.removeById(id);

        return  R.ok(remove);
    }

    @GetMapping("/getSkuListByKeyWord/{keyword}")
    public R<List<CommonSelectVo>> getSkuListByKeyWord(@PathVariable String keyword){

        List<CommonSelectVo> vos = pmsSkuInfoService.getSkuListByKeyWord(keyword);

        return  R.ok(vos);
    }
}

